<script setup>
import { ref,computed } from 'vue'
import * as indexdata from '@/api/indexdata.js';
// import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { Document,CameraFilled,PictureFilled,Dish } from '@element-plus/icons-vue';
const size = ref('')
const tableData = ref([]);

// 轮播图
const imgList = ref([
    'https://pic.rmb.bdstatic.com/bjh/bb82a58025d/250103/a019e9078fc2f67bcf4e568c3fb995c2.jpeg',
    'https://img1.baidu.com/it/u=351836846,4137059473&fm=253&fmt=auto&app=120&f=JPEG?w=1457&h=800',
])


const jinquList = ref([])

const xiaochiList = ref([])

const jingdianList = ref([])

const gonggaoData = ref('')

const centerDialogVisible = ref(false);

const get_tableData = async () => {
    const param = {
        currentPage:1,
    }
    const res = await indexdata.findfingonggaoService(param)
    const data = res.data
    tableData.value = data.slice(0,6)
}

const get_jinquList = async () => {
    const param = {
        currentPage:1,
    }
    const res = await indexdata.articleJinquListService(param)
    const data = res.data
    jinquList.value = data.slice(0,4)
}

const get_xiaochiList = async () => {
    const param = {
        currentPage:1,
    }
    const res = await indexdata.articleMeishiListService(param)
    const data = res.data
    xiaochiList.value = data.slice(0,4)
}

const get_jindianList = async () => {
    const param = {
        currentPage:1,
    }
    const res = await indexdata.articleJindianListService(param)
    const data = res.data
    jingdianList.value = data.slice(0,4)
}


get_jinquList()

get_xiaochiList()

get_jindianList()

get_tableData()

const findMessage = (row)=>{
    gonggaoData.value = row.content;
    centerDialogVisible.value = true;
}

const formatDate = (date) => {
  if (!date) return '';
  const d = new Date(date);
  return d.toLocaleDateString(); // 根据需求你可以选择不同的格式化方式
};

</script>
<template>

<el-row :gutter="20" class="custom-row">
    <el-col :span="4">
    </el-col>
    <el-col :span="8">
        <div class="grid-content ep-bg-purple" >
            <el-carousel :interval="5000" arrow="always">
                <!-- <el-carousel-item v-for="(item, index) in imgList" :key="index">
                <el-image :src="item" lazy />
                </el-carousel-item> -->
                <el-carousel-item v-for="(item, index) in imgList" :key="index">
                <img :src="item" alt="carousel image" style="width: 100%; height: 400px; object-fit: cover;" />
                </el-carousel-item>
            </el-carousel>
        </div>
    </el-col>
    <el-col :span="8">
        <div style="display: flex;align-items: center;margin-bottom: -2%;">
            <el-icon color="#409EFC" size="30">
                <Document/>
            </el-icon>
            <p>系统公告</p>
        </div>
        <hr style="border-bottom: 2px solid blue;">
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="" width="180">
                <template #default="{ row }">
                    <span @click="findMessage(row)">{{ row.title }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="createTime" label="" align="right" >
                <template #default="row">
                    {{ formatDate(row.row.createTime) }}
                </template>
            </el-table-column>
        </el-table>
    </el-col>
    <el-col :span="4">
    </el-col>
</el-row>
<el-row :gutter="50" class="custom-row">
    <el-col :span="4"></el-col>
    <el-col :span="16">
        <div style="display: flex;align-items: center;margin-bottom: -1%;">
            <el-icon color="#409EFC" size="30">
                <CameraFilled />
            </el-icon>
            <p>特色景区</p>
        </div>
        <hr style="border-bottom: 2px solid blue;">
        <el-row :gutter="20">
            <el-col :span="6" class="col-item" v-for="(item,index) in jinquList" :key="index">
                <img :src="item.img" class="item-img" alt="carousel image" />
                <div class="item-name">  {{ item.name }}</div>
                <div class="item-content">{{ item.content }}</div>
            </el-col>
        </el-row>
    </el-col>
    <el-col :span="4"></el-col>
</el-row>
<el-row :gutter="20" class="custom-row">
    <el-col :span="4"></el-col>
    <el-col :span="16">
        <div style="display: flex;align-items: center;margin-bottom: -1%;">
            <el-icon color="#409EFC" size="30">
                <Dish />
            </el-icon>
            <p>特色小吃</p>
        </div>
        <hr style="border-bottom: 2px solid blue;">
        <el-row :gutter="20">
            <el-col :span="6" class="col-item" v-for="(item,index) in xiaochiList" :key="index">
                <img :src="item.img" class="item-img" alt="carousel image" />
                <div class="item-name">  {{ item.name }}</div>
                <div class="item-content">{{ item.content }}</div>
            </el-col>
        </el-row>
    </el-col>
    <el-col :span="4"></el-col>
</el-row>
<el-row :gutter="20" class="custom-row">
    <el-col :span="4"></el-col>
    <el-col :span="16">
        <div style="display: flex;align-items: center;margin-bottom: -1%;">
            <el-icon color="#409EFC" size="30">
                <PictureFilled />
            </el-icon>
            <p>特色景点</p>
        </div>
        <hr style="border-bottom: 2px solid blue;">
        <el-row :gutter="20">
            <el-col :span="6" class="col-item" v-for="(item,index) in jingdianList" :key="index">
                <img :src="item.img" class="item-img" alt="carousel image" />
                <div class="item-name">  {{ item.name }}</div>
                <div class="item-content">{{ item.content }}</div>
            </el-col>
        </el-row>
    </el-col>
    <el-col :span="4"></el-col>
</el-row>


<el-dialog
    v-model="centerDialogVisible"
    title="系统公告"
    width="30%"
    align-center>
    <span>{{ gonggaoData }}</span>
    <template #footer>
        <span class="dialog-footer">
        <el-button type="primary" @click="centerDialogVisible = false">
            确认
        </el-button>
        </span>
    </template>
</el-dialog>

</template>
<style scoped>
.gonggao{
    border-bottom: 2px solid blue;
}
.custom-row {
  margin-bottom: 20px;
}
.item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  margin-bottom: 10px;
}

.col-item {
  border: 1px solid #ddd; /* 给整个el-col加边框 */
  padding: 10px;
  text-align: center; /* 居中对齐 */
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* 使得内容均匀分布 */
  height: 100%; /* 保证col的高度占满 */
}

.item-name {
    font-size: 14px;
    font-weight: bold;
  display: block;
}

.item-content {
    margin-top: 5%;
    font-size: 14px;
    text-align: left;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 限制行数为 2 行 */
    line-clamp: 3; /* 标准属性 */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal; /* 保证文本换行 */
    max-height: 40px; /* 限制高度为 40px，防止过多内容 */
}

</style>